package com.ruoyi.bizsys.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.bizsys.domain.AwardActGroupRelation;
import com.ruoyi.bizsys.service.IAwardActGroupRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动-分组关联Controller
 *
 * @author african-loan
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/award/actGroupRelation")
public class AwardActGroupRelationController extends BaseController {
    @Autowired
    private IAwardActGroupRelationService awardActGroupRelationService;

/**
 * 查询活动-分组关联列表
 */
@PreAuthorize("@ss.hasPermi('bizsys:relation:list')")
@GetMapping("/list")
        public TableDataInfo list(AwardActGroupRelation awardActGroupRelation) {
        startPage();
        List<AwardActGroupRelation> list = awardActGroupRelationService.selectAwardActGroupRelationList(awardActGroupRelation);
        return getDataTable(list);
    }
    
    /**
     * 导出活动-分组关联列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:relation:export')")
    @Log(title = "活动-分组关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AwardActGroupRelation awardActGroupRelation) {
        List<AwardActGroupRelation> list = awardActGroupRelationService.selectAwardActGroupRelationList(awardActGroupRelation);
        ExcelUtil<AwardActGroupRelation> util = new ExcelUtil<AwardActGroupRelation>(AwardActGroupRelation.class);
        return util.exportExcel(list, "relation");
    }

    /**
     * 获取活动-分组关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('bizsys:relation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(awardActGroupRelationService.selectAwardActGroupRelationById(id));
    }

    /**
     * 新增活动-分组关联
     */
    @PreAuthorize("@ss.hasPermi('bizsys:relation:add')")
    @Log(title = "活动-分组关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwardActGroupRelation awardActGroupRelation) {
        return toAjax(awardActGroupRelationService.insertAwardActGroupRelation(awardActGroupRelation));
    }

    /**
     * 修改活动-分组关联
     */
    @PreAuthorize("@ss.hasPermi('bizsys:relation:edit')")
    @Log(title = "活动-分组关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwardActGroupRelation awardActGroupRelation) {
        return toAjax(awardActGroupRelationService.updateAwardActGroupRelation(awardActGroupRelation));
    }

    /**
     * 删除活动-分组关联
     */
    @PreAuthorize("@ss.hasPermi('bizsys:relation:remove')")
    @Log(title = "活动-分组关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(awardActGroupRelationService.deleteAwardActGroupRelationByIds(ids));
    }
}
